package com.sgb.kjwl.viewmodel.enterprise;

import androidx.core.util.Pair;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.ProfessionalTeamDetailEntity2;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamDetailActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamPictureActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ProfessionalTeamDetailModel extends BaseViewModel {

    private ProfessionalTeamDetailActivity professionalTeamDetailActivity;

    public ProfessionalTeamDetailModel(ProfessionalTeamDetailActivity professionalTeamDetailActivity) {
        this.professionalTeamDetailActivity = professionalTeamDetailActivity;
    }

    public void getTeamQueryDetail(long id) {
        professionalTeamDetailActivity.loading();
        DialogHelper.showProgressDialog(professionalTeamDetailActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTeamDetail(id).enqueue(new Callback<BaseEntity<ProfessionalTeamDetailEntity2>>() {
            @Override
            public void onResponse(Call<BaseEntity<ProfessionalTeamDetailEntity2>> call, Response<BaseEntity<ProfessionalTeamDetailEntity2>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    professionalTeamDetailActivity.setShowDetails(response.body().getData());
                    professionalTeamDetailActivity.success();
                } else {
                    professionalTeamDetailActivity.error();
                    MToast.showToast(professionalTeamDetailActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ProfessionalTeamDetailEntity2>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                professionalTeamDetailActivity.error();
            }
        });
    }

    public void clickIntent(int teamNo){
        ActivityJump.jumpToActivity(professionalTeamDetailActivity, ProfessionalTeamPictureActivity.class, Pair.create("teamNo",teamNo));
    }

    public String getImageOne(ProfessionalTeamDetailEntity2.ImagesBean imagesBean){
        if (imagesBean == null || imagesBean.getList().size()<=0){
            return "";
        }
        return imagesBean.getList().get(0).getUpload_pic();
    }
}
